﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Xml;
using System.IO;

namespace MonsterMashRegistry
{
    public partial class UserLinks : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            String username = Session["Username"].ToString();
            String password = Session["Password"].ToString();

            xDB_SOAP.XhiveServerSessionIfClient client = new MonsterMashRegistry.xDB_SOAP.XhiveServerSessionIfClient();

            try
            {
                String sessionID = client.connect(username, password, "DL_Monster_Mash_XML");
                String linksDoc = client.getDocument(sessionID, "/" + username + "/links.xml", null, null);

                if (String.IsNullOrEmpty(linksDoc))
                {
                    return;
                }

                XmlDocument doc = new XmlDocument();
                doc.LoadXml(linksDoc);

                XmlNodeList topNodes = doc.GetElementsByTagName("Links");
                XmlNode topNode = topNodes[0];

                foreach (XmlNode linkNode in topNode.ChildNodes)
                {
                    TableRow row1 = new TableRow();
                    TableCell titleCell = new TableCell();
                    titleCell.Text = linkNode.Name;

                    row1.Cells.Add(titleCell);
                    m_LinksTable.Rows.Add(row1);

                    foreach (XmlNode paramNode in linkNode.ChildNodes)
                    {
                        TableRow paramRow = new TableRow();
                        TableCell nameCell = new TableCell();
                        nameCell.Text = paramNode.Name;
                        paramRow.Cells.Add(nameCell);
                        TableCell valueCell = new TableCell();
                        valueCell.Text = paramNode.InnerText;
                        paramRow.Cells.Add(valueCell);
                        m_LinksTable.Rows.Add(paramRow);
                    }

                }


            }
            catch (Exception ex)
            {

            }

        }

        protected void m_AddButton_Click(object sender, EventArgs e)
        {
            Response.Redirect("AddNewLink.aspx");
        }
    }
}
